package com.laikan.reader.core.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.Search;

import java.util.ArrayList;

public class SearchAdapter extends LaikanBaseAdapter<Search> {

    ViewHolder holder = null;

    public SearchAdapter(Context context,  ArrayList<Search> moreList) {
        super(context, moreList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.lk_searchnew_item, null);
            convertView.setTag(holder);

            holder.book_name = (TextView)convertView.findViewById(R.id.book_name);

            holder.book_auto = (TextView)convertView.findViewById(R.id.book_auto);

            holder.rank_num = (TextView)convertView.findViewById(R.id.rank_num);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }

        switch (position) {
            case 0:
                holder.rank_num.setText("1");
                holder.rank_num.setBackgroundResource(R.drawable.rank_bg_red);
                break;
            case 1:
                holder.rank_num.setText("2");
                holder.rank_num.setBackgroundResource(R.drawable.rank_bg_org);
                break;
            case 2:
                holder.rank_num.setText("3");
                holder.rank_num.setBackgroundResource(R.drawable.rank_bg_yellow);
                break;

            default:
                holder.rank_num.setText(position + 1 + "");
                holder.rank_num.setBackgroundResource(R.drawable.rank_bg_gray);
                break;
        }

        holder.book_auto.setText(datas.get(position).getAuthorName());
        holder.book_name.setText(datas.get(position).getName());
        return convertView;
    }

    private class ViewHolder {

        public TextView book_name, book_auto, rank_num;
    }

}
